package serve

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"strconv"
	"svvenus/util/env"
)

// HttpServe
// @Description: http服务
type HttpServe struct {
	Port  int
	Route *gin.Engine
}

// NewHttpServe 创建
// @param port
// @param rt
// @return *HttpServe
func NewHttpServe(port int, rt *gin.Engine) *HttpServe {
	if env.IsProd() {
		gin.SetMode(gin.ReleaseMode)
	} else if env.IsTest() {
		gin.SetMode(gin.TestMode)
	} else {
		gin.SetMode(gin.DebugMode)
	}
	fmt.Println("SvGin.Mode", gin.Mode())

	s := &HttpServe{
		Port:  port,
		Route: rt,
	}
	return s
}

// Start 启动
// @receiver sv
func (sv *HttpServe) Start() {
	_ = sv.Route.Run(":" + strconv.Itoa(sv.Port))
}
